﻿namespace ExamV5.WorkExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmLookPaper : Page
    {
        protected GridView DataGridA;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        protected Label labATitle;
        protected Label labCountFen;
        protected Label labExamName;
        protected Label labResult;
        protected Label labTitle;
        private PublicFun publicFun_0 = new PublicFun();
        private string string_0 = "";
        private string[] string_1;
        private string[] string_2;

        private void method_0()
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(string.Concat(new object[] { "select * from WorkCheckPaper where UserCode='", this.string_0, "' and PaperID=", this.int_0 }), connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (!reader.Read())
            {
                base.Response.Write("<script>alert('没有保存试卷并强行退出，暂无详细试卷批改记录！')</script>");
            }
            else
            {
                this.string_1 = reader["RubricSWrite"].ToString().Trim().Split(new char[] { '|' });
                this.string_2 = reader["RubricSFen"].ToString().Trim().Split(new char[] { '|' });
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
        }

        private void method_1()
        {
            string str2 = "";
            string str3 = "";
            string str4 = "";
            string str5 = "";
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlDataReader reader = new SqlCommand(string.Concat(new object[] { "select c.GetCountFen,b.SortInfo,a.ExamName,a.SubjectName,a.RubricDist,a.MemoDist,b.RubricS from WorkPaperInfo a ,WorkPaperData b,WorkExamUser c ,WorkCheckPaper d where d.PaperID=a.ID and d.UserCode=c.UserCode and  c.PaperID=b.PaperID and c.UserCode=b.UserCode and a.ID=b.PaperID  and b.UserCode='", this.string_0, "' and a.ID=", this.int_0 }), connection).ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                this.labExamName.Text = reader["ExamName"].ToString();
                this.labCountFen.Text = reader["GetCountFen"].ToString();
                str2 = reader["RubricDist"].ToString();
                str3 = reader["MemoDist"].ToString();
                str4 = reader["SortInfo"].ToString();
                str5 = reader["RubricS"].ToString();
            }
            connection.Close();
            connection.Dispose();
            string[] strArray = str2.Split(new char[] { '#' });
            string[] strArray3 = str3.Split(new char[] { '#' });
            string[] strArray4 = str4.Split(new char[] { '#' });
            int num = 0;
            if (strArray.Length < 1)
            {
                base.Response.Write("<script>alert('没有找到相关数据！')</script>");
            }
            else if (strArray[0] != "0")
            {
                num++;
                this.labATitle.Visible = true;
                this.labATitle.Text = "<br>&nbsp;<b>一、测评试题</b>&nbsp;(共<font color='#ff0000'>" + strArray[0] + "</font>题,说明:" + strArray3[0] + ")<br><br>";
                this.method_2(str5, strArray4[0]);
            }
        }

        private void method_2(string string_3, string string_4)
        {
            this.DataGridA.Visible = true;
            int num = 1;
            string selectCommandText = "Select ID,SubjectID,RubricType,RubricTitle,OptionAnswer,OKAnswer from WorkRubric where RubricType='A'";
            selectCommandText = selectCommandText + " and ID in(" + string_3.Replace("#", ",") + "0) order by " + string_4;
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "SRubric");
            this.DataGridA.DataSource = dataSet.Tables["SRubric"].DefaultView;
            this.DataGridA.DataBind();
            for (int i = 0; i < this.DataGridA.Rows.Count; i++)
            {
                string[] strArray3 = dataSet.Tables["SRubric"].Rows[i]["OptionAnswer"].ToString().Split(new char[] { '#' });
                Label label5 = (Label) this.DataGridA.Rows[i].FindControl("labADataTitle");
                label5.Text = num.ToString() + "、" + label5.Text.ToString();
                Label label4 = (Label) this.DataGridA.Rows[i].FindControl("labChooseDataA");
                if (strArray3[0].Trim() != "")
                {
                    label4.Text = label4.Text + "<br>A、" + strArray3[0];
                }
                if (strArray3[1].Trim() != "")
                {
                    label4.Text = label4.Text + "<br>B、" + strArray3[1];
                }
                if (strArray3[2].Trim() != "")
                {
                    label4.Text = label4.Text + "<br>C、" + strArray3[2];
                }
                if (strArray3[3].Trim() != "")
                {
                    label4.Text = label4.Text + "<br>D、" + strArray3[3];
                }
                if (strArray3[4].Trim() != "")
                {
                    label4.Text = label4.Text + "<br>E、" + strArray3[4];
                }
                if (strArray3[5].Trim() != "")
                {
                    label4.Text = label4.Text + "<br>F、" + strArray3[5];
                }
                num++;
                Label label2 = (Label) this.DataGridA.Rows[i].FindControl("labAUserAnswer");
                Label label3 = (Label) this.DataGridA.Rows[i].FindControl("labAUserFen");
                label2.Text = "<FONT color='red'>考生答案:</FONT>" + this.string_1[i];
                label3.Text = "<FONT color='red'>具体得分:</FONT>" + this.string_2[i];
                Label label = (Label) this.DataGridA.Rows[i].FindControl("labAOKAnswer");
                string[] strArray2 = label.Text.Trim().Split(new char[] { '#' });
                label.Text = "<FONT color='red'>参考分值:</FONT><br>";
                for (int j = 0; j < strArray2.Length; j++)
                {
                    string str3 = j.ToString();
                    switch (str3)
                    {
                        case null:
                        {
                            continue;
                        }
                        case "0":
                        {
                            if (strArray2[j].Trim() != "")
                            {
                                label.Text = label.Text + "A、" + strArray2[j].Trim() + "<br>";
                            }
                            continue;
                        }
                        case "1":
                        {
                            if (strArray2[j].Trim() != "")
                            {
                                label.Text = label.Text + "B、" + strArray2[j].Trim() + "<br>";
                            }
                            continue;
                        }
                        case "2":
                        {
                            if (strArray2[j].Trim() != "")
                            {
                                label.Text = label.Text + "C、" + strArray2[j].Trim() + "<br>";
                            }
                            continue;
                        }
                        case "3":
                        {
                            if (strArray2[j].Trim() != "")
                            {
                                label.Text = label.Text + "D、" + strArray2[j].Trim() + "<br>";
                            }
                            continue;
                        }
                        case "4":
                            if (strArray2[j].Trim() != "")
                            {
                                label.Text = label.Text + "E、" + strArray2[j].Trim() + "<br>";
                            }
                            break;
                    }
                    if (str3 == "4")
                    {
                        if (strArray2[j].Trim() != "")
                        {
                            label.Text = label.Text + "E、" + strArray2[j].Trim() + "<br>";
                        }
                    }
                    else if ((str3 == "5") && (strArray2[j].Trim() != ""))
                    {
                        label.Text = label.Text + "F、" + strArray2[j].Trim() + "<br>";
                    }
                }
            }
            adapter.Dispose();
            dataSet.Clear();
            dataSet.Dispose();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["PaperID"].ToString());
                if (this.httpCookie_2.Value == "A")
                {
                    this.string_0 = this.httpCookie_0.Value;
                    if (this.publicFun_0.GetValues("select LookPaper from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "LookPaper") == "N")
                    {
                        base.Response.Write("<script>alert('查看试卷批改明细权限未开放！')</script>");
                        return;
                    }
                }
                else
                {
                    this.string_0 = base.Server.UrlDecode(base.Request["UserCode"].ToString());
                }
                if (!base.IsPostBack)
                {
                    this.labTitle.Text = "查看【" + this.publicFun_0.GetValues("select UserName from UserInfo where UserCode='" + this.string_0 + "'", "UserName") + "(" + this.string_0 + ")】测评试卷批改明细";
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "--查看测评考卷批改明细";
                        this.method_0();
                        this.method_1();
                        string values = this.publicFun_0.GetValues(string.Concat(new object[] { "select ReuleName from WorkGradeReule where  PaperID=", this.int_0, " and MinValue<=", this.labCountFen.Text.Trim(), " and ", this.labCountFen.Text.Trim(), "<=MaxValue" }), "ReuleName");
                        if (values.Trim() == "")
                        {
                            values = "暂未找到相对应的测评结果！";
                        }
                        this.labResult.Text = values;
                    }
                    else
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                }
            }
        }
    }
}

